/*Inter-group interaction and attitudes to migrants
The Journal of Politics, 2023
Mintewab Bezabih, Sosina Bezu, Tigabu Getahun, Ivar Kolstad, Päivi Lujala, and Arne Wiig
Correspondence: ivar.kolstad@nhh.no
Last Modification 08.08.2023
Stata Version 17.0
Operating System: Microsoft Windows 10 Enterprise 
*/


/*Programmes that may need to be installed
	*estout
	*rwolf2
	*orth_out
*/


/*Set working directory

	*define directoy to folder were replication was unzipped
	*cd "Your Working Directory here"

*/



*****************************************************
*****************************************************
**Main text analyses*********************************
*****************************************************
*****************************************************

use ${PROCESSED}/ethiopia_replication,clear

**********************************************************
**Table 1 and associated results reported in Section 4.1**
**********************************************************


global controls ="age gender head education occupation_skilled_employee occupation_unskilled_employee occupation_day_labourer occupation_farmer occupation_self_no_employees occupation_self_with_employees asset_index own_migration_history village*"

global M_controls ="M_age M_gender M_education M_occupation_skilled_employee M_occupation_unskilled_employee M_occupation_day_labourer M_occupation_farmer M_occupation_self_no_employees M_occupation_self_with_employees M_asset_index "


reg attitude_to_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh, ro
estimates store main_1

**tests for equality of treatment effects reported in Section 4.1

test treatment_hm_neutral = treatment_hh

test treatment_hm_neutral = treatment_hm_economic

test treatment_hm_neutral = treatment_hm_identity


qui reg attitude_to_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh ${controls}, ro
estimates store main_2


qui reg attitude_to_migrants treatment_hm_economic treatment_hm_identity ${controls} ${M_controls}, ro
estimates store main_3

**creating Table 1 (which contains abbreviated output excluding covariate estimates, with full results reported in Table C1 in Appendix C)

estout main_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(village*)


**control group standard deviation used to calculate effects sizes
summ attitude_to_migrants if treatment_hcontrol==1



**********************************************************
**Table 2 and associated results reported in Section 4.2**
**********************************************************


reg M_perceived_host_attitude M_treatment_hm_neutral M_treatment_hm_economic M_treatment_hm_identity, ro
estimates store M_main_1


qui reg M_perceived_host_attitude M_treatment_hm_neutral M_treatment_hm_economic M_treatment_hm_identity ${M_controls}, ro
estimates store M_main_2


qui reg M_perceived_host_attitude  M_treatment_hm_economic M_treatment_hm_identity ${M_controls} ${controls}, ro
estimates store M_main_3


**creating Table 2 (which contains abbreviated output excluding covariate estimates, with full results reported in Table C6 in Appendix C)

estout M_main_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(village*)




****************************************************************
****************************************************************
**Supplementary materials analyses******************************
****************************************************************
****************************************************************


************
**Table A3**
************

qui reg attitude_to_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh, ro
summ attitude_to_migrants ${controls} if e(sample), sep(0)

**summary statistics for components of asset index and monthly income reported in main text
summ surveyCC_ownfarm surveyCC_house surveyCC_fridge surveyCC_tv surveyCC_bicycle surveyCC_motor_vehicle surveyCC_car surveyCC_mobile surveyCC_computer surveyCC_rooms surveyCC_income_mth if e(sample)
summ surveyCC_rooms if e(sample),det


************
**Table A4**
************

qui reg attitude_to_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh, ro
orth_out ${controls} if e(sample), by(surveyidentificationtreatment) se  test count vce(robust)


************
**Table A5**
************

qui reg M_perceived_host_attitude M_treatment_hm_neutral M_treatment_hm_economic M_treatment_hm_identity, ro
summ M_perceived_host_attitude  ${M_controls} if e(sample), sep(0)

**summary statistics for components of asset index and monthly income reported in main text
summ M_bicycle M_mobile M_income_mth if e(sample)


************
**Table A6**
************
qui reg M_perceived_host_attitude M_treatment_hm_neutral M_treatment_hm_economic M_treatment_hm_identity, ro
orth_out ${M_controls} if e(sample), by(M_surveyidentificationtreat) se  test count vce(robust)



************
**Table C1**
************

**code given above as for Table 1 in main text

**correcting for multiple hypothesis testing in column three using the Romano and Wolf (2016) approach
**variable names shortened for this analysis

preserve
ren attitude_to_migrants attitude
ren treatment_hm_economic treatment_hm_ec
ren treatment_hm_identity treatment_hm_id
ren occupation_skilled_employee occ_skilled 
ren occupation_unskilled_employee occ_unskilled
ren occupation_day_labourer occ_day 
ren occupation_self_no_employees occ_self_no
ren occupation_self_with_employees occ_self_with
ren own_migration_history own_migration_hist
ren M_occupation_skilled_employee M_occ_skilled
ren M_occupation_unskilled_employee M_occ_unskilled
ren M_occupation_day_labourer M_occ_day
ren M_occupation_self_no_employees M_occ_self_no
ren M_occupation_self_with_employees M_occ_self_with

rwolf2 (reg attitude treatment_hm_ec treatment_hm_id age gender head education occ_skilled occ_unskilled occ_day occupation_farmer occ_self_no occ_self_with asset_index own_migration_hist village* M_age M_gender M_education M_occ_skilled M_occ_unskilled M_occ_day M_occupation_farmer M_occ_self_no M_occ_self_with M_asset_index,ro), indepvars(M_age M_gender M_education M_occ_skilled M_occ_unskilled M_occ_day M_occupation_farmer M_occ_self_no M_occ_self_with M_asset_index) seed(876) usevalid reps(1000)

restore



************
**Table C2**
************

qui reg attitude_to_migrants any__migrant_treatment treatment_hh, ro
estimates store any_1
test any__migrant_treatment = treatment_hh

qui reg attitude_to_migrants any__migrant_treatment  treatment_hh ${controls}, ro
estimates store any_2
test any__migrant_treatment = treatment_hh

estout any_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(${controls})



************
**Table C3**
************

qui reg attitude_to_migrants  treatment_hm_economic treatment_hm_identity treatment_hh correct_guesses, ro
estimates store guesses_attitudes_1

qui reg attitude_to_migrants  treatment_hm_economic treatment_hm_identity treatment_hh ${controls} correct_guesses, ro
estimates store guesses_attitudes_2

estout guesses_attitudes_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(${controls})



************
**Table C4**
************

reg identification_with_migrant treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh ${controls}, ro
estimates store mech_1

reg plight_of_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh ${controls}, ro
estimates store mech_2

reg contribution_of_migrants treatment_hm_neutral treatment_hm_economic treatment_hm_identity treatment_hh ${controls}, ro
estimates store mech_3

estout mech_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(${controls})


**correcting for multiple hypothesis testing using the Romano and Wolf (2016) approach
**p-values in squared brackets in Table C4
**variable names shortened for this analysis

preserve
ren identification_with_migrant ident
ren plight_of_migrants plight
ren contribution_of_migrants contri
ren treatment_hm_economic treatment_hm_ec
ren treatment_hm_neutral treatment_hm_n
ren treatment_hm_identity treatment_hm_id
ren occupation_skilled_employee occ_skilled 
ren occupation_unskilled_employee occ_unskilled
ren occupation_day_labourer occ_day 
ren occupation_self_no_employees occ_self_no
ren occupation_self_with_employees occ_self_with
ren own_migration_history own_migration_hist
ren M_occupation_skilled_employee M_occ_skilled
ren M_occupation_unskilled_employee M_occ_unskilled
ren M_occupation_day_labourer M_occ_day
ren M_occupation_self_no_employees M_occ_self_no
ren M_occupation_self_with_employees M_occ_self_with


rwolf2 (reg ident treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh age gender head education occ_skilled occ_unskilled occ_day occupation_farmer occ_self_no occ_self_with asset_index own_migration_hist village* ,ro) (reg plight treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh age gender head education occ_skilled occ_unskilled occ_day occupation_farmer occ_self_no occ_self_with asset_index own_migration_hist village* ,ro) (reg contri treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh age gender head education occ_skilled occ_unskilled occ_day occupation_farmer occ_self_no occ_self_with asset_index own_migration_hist village* ,ro) , indepvars(treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh, treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh, treatment_hm_n treatment_hm_ec treatment_hm_id treatment_hh ) seed(876) usevalid reps(1000)

restore



************
**Table C5**
************

gen M_correct_guesses_economic=M_correct_guesses*treatment_hm_economic
gen M_correct_guesses_identity=M_correct_guesses*treatment_hm_identity

qui reg correct_guesses M_correct_guesses M_correct_guesses_economic M_correct_guesses_identity treatment_hm_economic treatment_hm_identity , ro
estimates store correlation_1

qui reg correct_guesses M_correct_guesses M_correct_guesses_economic M_correct_guesses_identity treatment_hm_economic treatment_hm_identity ${controls}, ro
estimates store correlation_2

estout correlation_*, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats (r2 N, fmt(%9.3f %9.0g)) starlevels(* 0.10 ** 0.05 *** 0.01) style(fixed) drop(${controls})


**correlation between correct guesses of paired players reported in text

pwcorr correct_guesses M_correct_guesses,sig



************
**Table C6**
************

**code given above as for Table 2 in main text






